package com.chen;

public class DemoString {
    public static void main(String[] args) {
          Thread t1=new Thread(new Runnable() {
              @Override
              public void run() {
                  test1("aaa");
              }
          });
          t1.start();
        try {
            Thread.sleep(100); //让t1线程先执行
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        Thread t2=new Thread(new Runnable() {
              @Override
              public void run() {
//                  test1("aaa");
                  test1(new String("aaa"));
              }
          });
        t2.start();
    }


    public  static void test1(String s){
        synchronized (s.intern()){
            System.out.println(Thread.currentThread().getName()+"---"+s);
            try {
                Thread.sleep(5000); //  让释放锁慢一点, 好观察
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
